package main

import (
	"github.com/boltdb/bolt"
	"whoscored/util/boltdb"
	"encoding/json"
	"whoscored/util/httputil"
	"fmt"
	"strconv"
	"strings"
)
//球队分析数据
func fetchTeam(dbKey string,stageId string,teamId string)  {
	url:="https://www.whoscored.com/stageteamstatfeed/?field=0&stageId="+stageId+"&teamId="+teamId
	headers:=map[string]string{
		"Pragma":"no-cache",
		//"Accept-Encoding": "gzip, deflate",
		"authority":"www.whoscored.com",
		"method":"GET",
		//"path":"/matchesfeed/?d="+date,
		"model-last-mode":"83BM8+f3zKvf8zEXKo1BdeZSV55d43vdRTF9aQFpw7Q=",
		"Cookie": "visid_incap_774904=iINxyvH1RSKdJVocn4S/cgCjZVoAAAAAQUIPAAAAAABSHTN36SBh6uyX/MAX4UcQ; _ga=GA1.2.586383088.1516610314; _gid=GA1.2.474294772.1516610314; permutive-id=ab06f937-443e-4432-83d7-ab4e2b556060; __gads=ID=6da13b6a195043d9:T=1516610316:S=ALNI_MZbNFloOsGT8E_4RTHnzKBgU0cuig; vg=821ae0b8-2b61-46af-a8b4-21331b25c154; ip=3063167153; vl=1:-8.00|2:CN|3:SICHUAN|4:|5:SICHUAN/|6:SICHUAN/CHENGDU|7:610015|!0; vd=chinatelecom.com.cn; incap_ses_426_774904=15veKoRYllgXGitXInXpBY3dZ1oAAAAAw8fCWnF86XeOCXEyA8ODBw==; OX_plg=pm; fq=1; incap_ses_199_774904=bS7fBgmt03tWcVe6Gf7CAiUUaFoAAAAAinDFOfMlTChewSKHDgjh1w==; vq=4425,4919,4919,4919,4919,4425,4919,4919,4919,4919,4425,4425,4425,4425,4919,4919,4919,4919,4425,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4919,4425,4919,4919,4425,4919,4919; permutive-session=%7B%22session_id%22%3A%2247b308e4-88f5-4b7c-9f4b-d31e4346839d%22%2C%22last_updated%22%3A%222018-01-24T07%3A10%3A22.698Z%22%7D; _psegs=%5B1920%2C1930%2C2126%2C2441%2C4848%2C3376%2C3377%2C1956%2C1907%2C2300%5D",
		"Connection": "keep-alive",
		"Accept": "application/json, text/javascript, */*; q=0.01",
		"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.11 NetType/WIFI Language/zh_CN",
		"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7",
		"X-Requested-With": "XMLHttpRequest",
		"referer":"https://www.whoscored.com/LiveScores",
	}
	data:=httputil.Request(url,"GET",headers,nil,)
	fmt.Println(data)
}

func main()  {
	//fetchTeam("","12497","171")

	s:=",252-2,108-5,206-4,81-3,74-22,177-21,155-13,182-77,31-95,233-85,225-17,252-7,11-68,45-162,165-41,212-40,81-6,250-12,250-30,247-36,"

	boltdb.ScanTx("matchs-2016", func(tx *bolt.Tx) {

		tx.ForEach(func(name []byte, b *bolt.Bucket) error {

			b.ForEach(func(k, v []byte) error {
				//fmt.Println(string(v))
				m:=make(map[string]interface{},0)
				json.Unmarshal(v,&m)
				s1:=m["region"].([]interface{})
				s2:=m["match"].([]interface{})
				ss:=strconv.FormatFloat(s1[4].(float64), 'f', -1, 64)
				region:=","+s1[1].(string)+"-"+ss+","
				if strings.Contains(s,region){
					stageId:=strconv.FormatFloat(s2[0].(float64), 'f', -1, 64)
					fmt.Println(stageId)
				}

				return nil
			})
			return nil
		})
	})
}
